<template>
  <view class="my-search-container" :style="{ 'background-color': bgcolor }">
    <view class="my-search-bigbox" :style="{ 'border-radius': radius + 'px' }">
      <!-- 地址定位 -->
      <view class="my-search-address" @click="FormBoxHandler">
        <view class="address-icon"></view>
        <text class="text">{{ searchCity }}</text>
      </view>
      <!-- 搜索触发框 -->
      <view class="my-search-box" @click="searchBoxHandler">
        <uni-icons type="search" size="30"></uni-icons>
        <text class="placeholder">搜索</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {};
  },
  props: {
    // 背景颜色
    bgcolor: {
      type: String,
      default: "#d4237a",
    },
    // 圆角尺寸
    radius: {
      type: Number,
      default: 20,
    },
  },
  // 方法
  methods: {
    searchBoxHandler() {
      //TosearchClick：引用了my-search组件的父组件所绑定的点击事件
      this.$emit("ToSearchClick");
      uni.navigateTo({
        url: "/subpkg/search/search",
        fail(error) {
          console.log(error);
        },
      });
    },
    FormBoxHandler() {
      this.$emit("ToFormClick");
      uni.navigateTo({
        url: "/subpkg/search-form/search-form",
        fail(error) {
          console.log(error);
        },
      });
    },
  },
  computed: {
    searchCity() {
      return this.$store.state.searchCity;
    }
  }
};
</script>

<style lang="scss">
.my-search-container {
  position: sticky;
  top: 0;
  z-index: 999;
  height: 70px;
  padding-top: 1px;
}

.my-search-bigbox {
  background-color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0px 18px;
  margin-top: 15px;
  height: 50px;
  color: #6b6163;

  .my-search-address {
    box-sizing: border-box;
    border-right: 1px solid #e79ea5;
    display: flex;
    justify-content: space-between;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 40%;
    height: 65%;
    padding: 0px 9px;

    .address-icon {
      width: 50%;
      height: 100%;
      background-image: url("../../../../static/icons/address.png");
      background-size: contain;
      background-repeat: no-repeat;
    }

    .text {
      width: 50%;
      height: 100%;
      font-size: 18px;
      line-height: 38px;
    }
  }

  .my-search-box {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
  }

  .placeholder {
    font-size: 18px;
  }
}
</style>
